package com.ruoyi.web.controller.operation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.AgentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GwAgent;
import com.ruoyi.system.service.IGwAgentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代理商Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@Api(description = "平台运营管理-代理商管理")
@RestController
@RequestMapping("/system/agent")
public class GwAgentController extends BaseController
{
    @Autowired
    private IGwAgentService gwAgentService;

    /**
     * 查询代理商列表
     */
    @ApiOperation("查询代理商列表-分页")
    @GetMapping("/list")
    public TableDataInfo list(GwAgent gwAgent)
    {
        startPage();
        List<AgentVO> list = gwAgentService.getList(gwAgent);
        return getDataTable(list);
    }

    /**
     * 查询代理商列表
     */
    @ApiOperation("查询代理商列表-无分页")
    @GetMapping("/agentList")
    public AjaxResult agentList(GwAgent gwAgent)
    {
        List<AgentVO> list = gwAgentService.getList(gwAgent);
        return AjaxResult.success(list);
    }

    /**
     * 导出代理商列表
     */
    @PreAuthorize("@ss.hasPermi('system:agent:export')")
    @Log(title = "代理商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwAgent gwAgent)
    {
        List<GwAgent> list = gwAgentService.selectGwAgentList(gwAgent);
        ExcelUtil<GwAgent> util = new ExcelUtil<GwAgent>(GwAgent.class);
        util.exportExcel(response, list, "代理商数据");
    }

    /**
     * 获取代理商详细信息
     */
    @ApiOperation("查询代理商详情")
    @PreAuthorize("@ss.hasPermi('system:agent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gwAgentService.selectGwAgentById(id));
    }

    /**
     * 新增代理商
     */
    @ApiOperation("新增代理商")
    @PreAuthorize("@ss.hasPermi('system:agent:add')")
    @Log(title = "代理商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwAgent gwAgent)
    {
        return gwAgentService.insertGwAgent(gwAgent);
    }

    /**
     * 修改代理商
     */
    @ApiOperation("修改代理商")
    @PreAuthorize("@ss.hasPermi('system:agent:edit')")
    @Log(title = "代理商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwAgent gwAgent)
    {
        return toAjax(gwAgentService.updateGwAgent(gwAgent));
    }

    /**
     * 删除代理商
     */
    @ApiOperation("删除代理商")
    @PreAuthorize("@ss.hasPermi('system:agent:remove')")
    @Log(title = "代理商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gwAgentService.deleteGwAgentByIds(ids));
    }
}
